﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ElementumForever
{
   public class EntityInfo
    {
        Dictionary<string, EntityInfo> _table;
        const string VALUE = "table:";
        bool isTable;
        public bool IsTable
        {
            get { return isTable; }
            set
            {
                isTable = value;
                if (_table == null && value)
                    _table = new Dictionary<string, EntityInfo>();
            }
        }
        public string Name { get; set; }
        public string Value { get; set; }

        public Dictionary<string, EntityInfo> Table
        {
            get
            {
                if (IsTable)
                    return _table;
                throw new Exception("Im not a table!!");
            }
            set
            {
                _table = value;
                IsTable = true;
                Value = VALUE + IsTable.ToString();
            }
        }

        public EntityInfo(string name, bool _isTable)
        {
            this.Name = name;
            this.Value = VALUE + _isTable.ToString();
            this.IsTable = _isTable;
        }

        public override string ToString()
        {
            if (IsTable)
                return VALUE + IsTable;
            return Name + "=\"" + Value + "\"";
        }

        public void AddElement(string name, string value)
        {
            if (_table == null)
                _table = new Dictionary<string, EntityInfo>();
            EntityInfo data = new EntityInfo(name, false);
            data.Value = value;
            _table.Add(name, data);
        }

        public void AddElement(string name, object value)
        {
            AddElement(name, value.ToString());
        }

        public void AddElement(string name, Microsoft.Xna.Framework.Color value)
        {
            EntityInfo data = new EntityInfo("color", true);
            data.AddElement("r", value.R);
            data.AddElement("g", value.G);
            data.AddElement("b", value.B);
            data.AddElement("a", value.A);
            AddElement(data);
        }

        public void AddElement(EntityInfo sceneData)
        {
            if (sceneData.IsTable)
                _table.Add(sceneData.Name, sceneData);
            else
                AddElement(sceneData.Name, sceneData.Value);
        }

    }
}
